import { ReactNode } from 'react';
import { notFound } from 'next/navigation';
import { fetchUserProfile } from '@/lib/api/account/profile';
import UserProfileStats from '../_component/UserProfileStats';
import UserProfileTabs from '../_component/UserProfileTabs';

type Props = {
	children: ReactNode;
	params: Promise<{ sid: string }>;
};

export default async function UserProfileTabsLayout({ children, params }: Props) {
	const { sid } = await params;
	const res = await fetchUserProfile(sid);

	if (!res.success || !res.data) {
		notFound();
	}

	const profile = res.data;

	return (
		<>
			<UserProfileStats profile={profile} />
			<UserProfileTabs memberSID={profile.memberSID} />
			{children}
		</>
	);
}